package org.netEase.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.netEase.dao.addressDao;
import org.netEase.dao.impl.addressDaoimpl;
import org.netEase.entity.address;

import com.alibaba.fastjson.JSON;

@WebServlet(urlPatterns = { "/gopaymenttwo.shtml" })
public class gopaymenttwo extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		int dzid = 1;
		String pp = "-1";
		String dizhi = "";
		String dzids = request.getParameter("dzids");
		String addid = request.getParameter("dzid");
		String pd = request.getParameter("pd");
		String hid = request.getParameter("hid");
		String address1 = request.getParameter("address1");
		String address2 = request.getParameter("address2");
		String address3 = request.getParameter("address3");
		String detailsaddress = request.getParameter("detailsaddress");
		String phone = request.getParameter("phone");
		String people = request.getParameter("people");
	
		addressDao addressDao = new addressDaoimpl();
		if (address1 != "" && address1!=null) {
			address address = new address();
			address.setAddress1(address1);
			address.setAddress2(address2);
			address.setAddress3(address3);
			address.setHid(Integer.parseInt(hid));
			address.setPhone(phone);
			address.setXiangxi(detailsaddress);
			address.setShname(people);
			
			addressDao.add(address);
		}
		response.setContentType("application/json;charset=utf-8");
		if(dzids != "" && dzids != null) {
			dzid = Integer.parseInt(dzids);
		}
		if (addid != "" && addid != null) {
			dzid = Integer.parseInt(addid);
		}
		if (pd != "" && pd != null) {

			pp = pd;
		}
		if (pp.equals("0")) {
			List<address> listadd = addressDao.getlistbyhid(Integer.parseInt(hid));
			dizhi = JSON.toJSONString(listadd);
		}
		if (pp.equals("-1")) {
			address address = addressDao.getbydzid(dzid, Integer.parseInt(hid));
			dizhi = JSON.toJSONString(address);
		}
		response.getWriter().write(dizhi);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}
}
